#include "ChatMessgeFramePainter.h"
#include "../../Message/TextChatMessage.h"
#include <QPainter>
#include <QBitmap>

CChatMessageFramePainter::CChatMessageFramePainter(){
    QPixmap pixmap;
    pixmap.load(":/image/qrc/image/headImage/16.bmp");

    m_pHeadImage = Pixmap2Round(pixmap, 15);
}

CChatMessageFramePainter::~CChatMessageFramePainter(){

}

void CChatMessageFramePainter::PainterContexnt(QPainter &painter){

     QRect trigRect = QRect(65, 22, 6, 9);
     QPointF points[3] = {
         QPointF(trigRect.x(), 30),
         QPointF(trigRect.x()+trigRect.width(), 25),
         QPointF(trigRect.x()+trigRect.width(), 35),
     };

     QColor col_Kuang(255,0,255);
     painter.setBrush(QBrush(col_Kuang));
     QPen pen;
     pen.setColor(col_Kuang);
     painter.setPen(pen);
     painter.drawPolygon(points, 3);

     QSize size = GetSize();
     QRect rectFrame(71, 20, size.width(), size.height() >> 1);

     // 框加边
     QColor col_KuangB(234, 234, 234);
     painter.setBrush(QBrush(col_KuangB));
     painter.drawRoundedRect(rectFrame.x()-1,rectFrame.y()-1,rectFrame.width()+2,rectFrame.height()+2,4,4);

     // 框
     QColor col_KuanA(255,255,255);
     painter.setBrush(QBrush(col_KuanA));
     painter.drawRoundedRect(rectFrame,4,4);

     if (nullptr != m_pChatMessgeUIPainter){
         m_pChatMessgeUIPainter->PainterContexnt(painter);
     }

}

void CChatMessageFramePainter::PainterFrame(void){
//    CChatMessage* pChatMessage = m_pChatMessage->GetMessage();
//    QSize size = pChatMessage->GetSize();
}

QPixmap CChatMessageFramePainter::Pixmap2Round(QPixmap& src, int radius){
    if (src.isNull()){
        return QPixmap();
    }

    QSize size(radius << 1, radius << 1);
    QBitmap mask(size);

    QPainter painter(&mask);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setRenderHint(QPainter::SmoothPixmapTransform);
    painter.fillRect(0, 0, size.width(), size.height(), Qt::white);

    painter.setBrush(QColor(0, 0, 0));
    painter.drawRoundedRect(0, 0, size.width(), size.height(), 99,99);

    QPixmap image = src.scaled(size);
    image.setMask(mask);
    return image;
}
